<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;

class LanguageSwitcher
{
  public function handle($request, Closure $next)
  {
    if (!Session::has('locale')) {
      Session::put('locale', env('APP_LOCALE'));
      Log::info('No locale found in session!');
    }
    App::setLocale(session('locale'));
    Log::info('Set locale to ' . session('locale'));

    return $next($request);
  }
}
